package a66weding.com.jiehuntong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.andview.refreshview.recyclerview.BaseRecyclerAdapter;

import org.xutils.x;

import java.util.List;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.beans.CasesDetail;
import a66weding.com.jiehuntong.beans.CateguryGridViewBean;
import a66weding.com.jiehuntong.beans.StoreDetailGuess;
import a66weding.com.jiehuntong.common.utils.ImageOptionsUtil;
import a66weding.com.jiehuntong.inner.OnItemClickLitener;
import a66weding.com.jiehuntong.widgets.CircularImage;

/**
 * Created by admin on 2016/7/30.
 */
public class StoreDetailAdapter extends BaseRecyclerAdapter<StoreDetailAdapter.ViewHolder> {
    private static final int TYPE_HEADER = 0;
    private static final int TYPE_ITEM = 1;
    //如果有点击事件请设置一个监听;
    private OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener)
    {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }
    private Context context;
    private List<StoreDetailGuess.DataBean> data;
    private  View headView;
    public StoreDetailAdapter(Context context, List<StoreDetailGuess.DataBean> data,View headView){
        this.context = context;
        if (data!=null){
            this.data = data;
        }
        this.headView = headView;

    }
    public void append(List<StoreDetailGuess.DataBean> data) {
        if (this.data != null) {
            this.data.addAll(data);
        } else {
            this.data = data;
        }
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder getViewHolder(View view) {
        return new ViewHolder(view);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        if (viewType==TYPE_HEADER){
         return  new ViewHolder(headView);
        }else if(viewType==TYPE_ITEM){
            View v = LayoutInflater.from(context).inflate(
                    R.layout.item_store_content, parent, false);
            return new ViewHolder(v);
        }
        return null;
    }

    @Override
    public int getAdapterItemViewType(int position) {
       if(isPositionHeader(position)){
           return TYPE_HEADER;
       }
        return TYPE_ITEM;

    }
    public boolean isPositionHeader(int position)
    {
        return position == 0;
    }
    @Override
    public void onBindViewHolder(final ViewHolder holder, int position, boolean isItem) {
        if (mOnItemClickLitener!=null){
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView,pos);
                }
            });
        }
        if (holder instanceof ViewHolder){
                if (position>0) {

                }

        }
    }

    @Override
    public int getAdapterItemCount() {
        if (data ==null){
            return 0;
        }
        return  data.size()+1;
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        public ViewHolder(View itemView) {
            super(itemView);

        }
    }

}
